﻿<?php
class SearchController extends Forum_Controller_Action
{
    public function indexAction() 
    {		
		$this->render();    
    }
    
    public function findAction(){
		$data = $this->_getParam('search');
		if(!isset($data['search_text']) || empty($data['search_text'])){
			Forum_Message::getInstance()->addError('Повідбивать би руки... ');
			return false;
		}
		$this->view->result = $this->_search($data);
		$this->render();
	}
	
	private function _search($data){
		$query = "SELECT 
					forum_search.user_id as user_id, 
					forum_search.user_name as user_name, 
					forum_search.thread_name as thread_name,
					forum_search.thread_id as thread_id,
					forum_search.message_text as message_text,
					forum_search.message_id as message_id
				  FROM
				  	forum_search
				  WHERE
				  	user_name LIKE '".$data."' OR
				  	thread_name LIKE '".$data."' OR
				  	message_text LIKE '".$data."';
				 ";
		return Forum::registry('db')->fetchAll($query);
	}
    
}
